﻿#ifndef MULTPLOT_H
#define MULTPLOT_H

#include <QWidget>
#include <qcustomplot.h>
#include <QVector>
#include <QMap>
#include "LineAssistance.h"
#include <QMouseEvent>
// #include "XxwTracer.h"


class QCustomPlot;

#define LIN_COLOR  QColor(0, 107, 176)
#define TEXT_COLOR QColor(235, 235, 235)
#define BACKGROUND_COLOR QColor(3, 22, 52)
#define BRUSH_COLOR QColor(255, 255, 255, 0)
#define LABEL_COLOR QColor(250,250,250)

enum PointType {
    DATA_POINT = 0,
    SMALL_POINT,
    BIG_POINT,
};

enum StyleDraw{
    S_NONE,
    S_LINE,
    S_PTS,
};

struct CoodRangs{
    double xmin;
    double xmax;
    double ymax;
    double ymin;
};



namespace Ui {
class MultPlot;
}

class MultPlot : public QWidget
{
    Q_OBJECT

public:
    explicit MultPlot(QWidget *parent = nullptr);
    ~MultPlot();
    QCustomPlot* getBody();
    void creatChart(int xInd,int yInd,std::string x,std::string y);
    void setTitles(std::string t1,std::string t2);

    void SetStyle(StyleDraw s);

    // 安装监听事件
    void installEvent(bool v);

    void SetGridVisible(bool v);

private:
    Ui::MultPlot *ui;
    CoodRangs rangs;

    void initUIs();
    void initAssistance();

    ///
      /// \brief 是否显示鼠标追踪器
      /// \return
      ///
      bool isShowTracer(){return m_isShowTracer;};

private:
    bool m_isShowTracer;//是否显示追踪器（鼠标在图中移动，显示对应的值）
    XxwTracer *m_xTracer;//x轴
    XxwTracer *m_yTracer;//y轴
    QList<XxwTracer *> m_dataTracers;//
    XxwTraceLine  *m_lineTracer;//直线


public:
    QMap<int,QVector<double>> curData; // 0.X1 1:Y1  2:X2 3.Y2
    QString XLable = "X";
    QString YLable = "Value";
    QString Title = "期望-实际";

    QSharedPointer<QCPAxisTickerFixed> xAxis; // x方向轴
    QSharedPointer<QCPAxisTickerFixed> yAxis; // y方向轴
    QSharedPointer<QCPTextElement> title; // y方向轴



protected:
    // void mouseMoveEvent(QMouseEvent *event) override;

    bool eventFilter(QObject *watched, QEvent *event) override;
public:

    ///
    /// \brief 设置是否显示鼠标追踪器
    /// \param show:是否显示
    ///
    void showTracer(bool show)
    {
        m_isShowTracer = show;
        if(m_xTracer)
            m_xTracer->setVisible(m_isShowTracer);
        foreach (XxwTracer *tracer, m_dataTracers)
        {
            if(tracer)
                tracer->setVisible(m_isShowTracer);
        }
        if(m_lineTracer)
            m_lineTracer->setVisible(m_isShowTracer);
    }
};

#endif // MULTPLOT_H
